package com.appkubes.mall.restful.application.customer.taobao.service.impl;

import com.appkubes.mall.core.entity.MallCustomerTaobao;
import com.appkubes.mall.core.service.impl.BaseMallCustomerTaobaoServiceImpl;
import com.appkubes.mall.restful.application.admin.account.dao.AdminAccountDao;
import com.appkubes.mall.restful.application.admin.admin.service.AdminService;
import com.appkubes.mall.restful.application.admin.binding.dao.AdminBindingDao;
import com.appkubes.mall.restful.application.customer.taobao.entity.dto.GoodsCollectDTO;
import com.appkubes.mall.restful.application.goods.taobao.dao.UserTaobaoCollectDao;
import com.appkubes.mall.restful.application.customer.taobao.service.CustomerTaobaoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 淘宝商品
 * @Date: 2020-01-12
 * @Version: V1.0
 */
@Service
public class CustomerTaobaoServiceImpl extends BaseMallCustomerTaobaoServiceImpl implements CustomerTaobaoService {
    @Autowired
    AdminService adminService;

    @Autowired
    AdminBindingDao adminBindingDao;

    @Autowired
    AdminAccountDao adminAccountDao;

    @Autowired
    UserTaobaoCollectDao userTaobaoCollectDao;

    public MallCustomerTaobao getCustomerTaobaoInfo(String customerKey){
        MallCustomerTaobao customerTaobao = new MallCustomerTaobao();
        customerTaobao.setCustomerKey(customerKey);
        MallCustomerTaobao customerTaobaoRes = this.getOneByEntity(customerTaobao);
        if(customerTaobaoRes == null){
            this.save(customerTaobao);
            return customerTaobao;
        }else{
            return customerTaobaoRes;
        }


    }

    @Override
    public List<GoodsCollectDTO> goodsCollectList(String customerKey, Integer sort, Page pageInfo) {
        return userTaobaoCollectDao.goodsCollectList(customerKey, sort, pageInfo);
    }

    @Override
    public Boolean modifyAlipayInfo(String customerKey, String alipayAccount, String alipayName) {
        MallCustomerTaobao entity = new MallCustomerTaobao();
        entity.setCustomerKey(customerKey);
        entity.setAlipay(alipayAccount);
        entity.setAlipayName(alipayName);
        return this.updateById(entity);
    }

    @Override
    public Boolean bindPid(String customerKey, String pid) {
        MallCustomerTaobao entity = new MallCustomerTaobao();
        entity.setCustomerKey(customerKey);
        entity.setPid(pid);
        return this.updateById(entity);
    }
}
